package com.xian.ucenter.controller.admin;


import cn.hutool.core.bean.BeanUtil;
import com.xian.ucenter.commons.Result;
import com.xian.ucenter.entities.User;
import com.xian.ucenter.entities.vo.UserLogin;
import com.xian.ucenter.entities.vo.UserVo;
import com.xian.ucenter.service.UserService;
import com.xian.ucenter.utils.ConstantUtil;
import com.xian.ucenter.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 用户管理表 前端控制器
 * </p>
 *
 * @author xian
 * @since 2022/07/23 02:59
 */
@RestController
@RequestMapping("/ucenter/admin/user")
public class UserController {
    @Autowired
    private UserService userService;
    @Autowired
    private RedisUtil redisUtil;
    @PostMapping("/addUser")
    public Result addUser(@RequestBody User user) {
        return userService.addUser(user) ? Result.ok() : Result.fail();
    }
    @PostMapping("/update")
    public Result updateUser(@RequestBody UserVo userVo) {
        User user = BeanUtil.copyProperties(userVo, User.class);
        if (userService.updateById(user)) {
            redisUtil.delete(ConstantUtil.LOGIN_USER_KEY+user.getId());
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
}
